package org.huangrui.juc.day03;

/**
 * @author hr
 * @createTime 2022-04-06 00:08
 */
public class T05_Contended {
//    @Contended
    private volatile long x;
//    @Contended
    private volatile long y;
    private static long COUNT = 10_0000_0000L;
    public static void main(String[] args) throws InterruptedException {
        T05_Contended t = new T05_Contended();
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < COUNT; i++) {
                t.x = i;
            }
        }, "input thread name");
        Thread t2 = new Thread(() -> {
            for (int i = 0; i < COUNT; i++) {
                t.y = i;
            }
        }, "input thread name");
        long start = System.nanoTime();
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        long end = System.nanoTime();
        System.out.println((end - start) /100_0000);
    }
}
